# 列表推导式实现if else功能
list1 = [i for i in range(20) if i%2 == 0]
list2 = [i if i > 3 else i+3 for i in range(10)]
print('if列表生成式list1:')
print(list1)
print('if else 列表生成式list2:')
print(list2)

# 生成器表达式实现if else功能
list3 = (i for i in range(10) if i % 2 == 1)
print('if生成器表达式list3:')
print(list(list3))
list4 = (i if i > 10 else i+10 for i in range(20))
print('if else生成器表达式list4:')
print(list(list4))